package com.asset.action;

import com.asset.pojo.User;

/**
 * Created by gongshaobo on 2017/1/13  10:55.
 */
public class LoginAction extends BaseAction {
    
	private static final long serialVersionUID = 1L;
	private User user;
    private String name;
    private String password;
    private User userTemp;
    private String operaRes;
    
    public String toLogin(){

       /* String company = "";
        company = company.replaceAll("\\n",",");
        String [] paces= company.split(",");
        boolean flag = true;
        List<String> city = new ArrayList<String>();
        for ( int i = 0 ; i < paces.length; i ++ ) {
            int testLenght = 0;
            for(String s:city){
                if(paces[i].equals(s)){
                    break;
                }else{
                    testLenght++;
                }
            }
            if(testLenght == city.size()){
                city.add(paces[i]);
            }
       }
        for(String s : city){
            Department department = new Department();
            department.setName(s);
            departService.addDepart(department);
        }
        System.out.print(city);*/
        return SUCCESS;
    }
    
    public String login(){
     User loginSuccUser = userService.getUserByLoginInfo(user.getLoginName(),user.getPassword());//通过用户名和密码查询，并且状态不为已删除	
        if(loginSuccUser != null){      
            getSession().setAttribute(UserKEY,loginSuccUser); 
            operaRes = "0";
        }else{
        	operaRes = "1";
        }
        return SUCCESS;
    }
    public String logout(){
        if(session != null){
            session.removeAttribute(UserKEY);
        }
        return SUCCESS;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public User getUserTemp() {
        return userTemp;
    }

    public void setUserTemp(User userTemp) {
        this.userTemp = userTemp;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

	public String getOperaRes() {
		return operaRes;
	}

	public void setOperaRes(String operaRes) {
		this.operaRes = operaRes;
	}
}
